<script setup lang="ts">
import { db } from './db/db'
import usersTypeData from './data/UsersTypeData'
import usersData from './data/UsersData'
import schoolData from './data/SchoolData'
import studentData from './data/StudentData'
import organizeData from './data/OrganizeData'
import salvationTypeData from './data/SalvationTypeData'
import organizeSalvationTypeData from './data/OrganizeSalvationTypeData'
import salvationData from './data/SalvationData'
import donationData from './data/DonationData'
import donationSubdivisionTypeData from './data/DonationSubdivisionTypeData'
import donationTypeData from './data/DonationTypeData'
import petImageData from './data/PetImageData'
import petSalvationPlanData from './data/PetSalvationPlanData'
import platformInformationData from './data/PlatformInformationData'
import commentData from './data/CommentData'
import collectionData from './data/CollectionData'
import organizeDetailData from './data/OrganizeDetailData'
import organizeImagesData from './data/OrganizeImagesData'

// 初始化数据
const initDb = async () => {
  const systemConfig = await db.systemConfig.where('configKey').equals('FIRST_INIT').toArray()
  console.log(systemConfig)
  if (systemConfig.length <= 0) {
    console.log('initDb')
    await db.systemConfig.add({
      configKey: 'FIRST_INIT',
      configValue: 'TRUE'
    })

    usersTypeData.forEach(async (v) => {
      await db.usersType.add(v)
    })

    usersData.forEach(async (v) => {
      await db.users.add(v)
    })

    schoolData.forEach(async (v) => {
      await db.school.add(v)
    })

    studentData.forEach(async (v) => {
      await db.student.add(v)
    })

    organizeData.forEach(async (v) => {
      await db.organize.add(v)
    })

    salvationTypeData.forEach(async (v) => {
      await db.salvationType.add(v)
    })

    organizeSalvationTypeData.forEach(async (v) => {
      await db.organizeSalvationType.add(v)
    })

    salvationData.forEach(async (v) => {
      await db.salvation.add(v)
    })

    petImageData.forEach(async (v) => {
      await db.petImage.add(v)
    })

    petSalvationPlanData.forEach(async (v) => {
      await db.petSalvationPlan.add(v)
    })

    platformInformationData.forEach(async (v) => {
      await db.platformInformation.add(v)
    })

    donationTypeData.forEach(async (v) => {
      await db.donationType.add(v)
    })

    donationSubdivisionTypeData.forEach(async (v) => {
      await db.donationSubdivisionType.add(v)
    })

    donationData.forEach(async (v) => {
      await db.donation.add(v)
    })

    commentData.forEach(async (v) => {
      await db.comment.add(v)
    })

    collectionData.forEach(async (v) => {
      await db.collection.add(v)
    })

    organizeDetailData.forEach(async (v) => {
      await db.organizeDetail.add(v)
    })

    organizeImagesData.forEach(async (v) => {
      await db.organizeImages.add(v)
    })
  }
}

initDb()

</script>
<template>
  <RouterView />
</template>
